#include "../source/common/detail.hpp"
#include "../source/client/rpc_client.hpp"
#include <bits/this_thread_sleep.h>

void callback(const Json::Value &result)
{
    ILOG("callback result: %d", result.asInt());
}
void rpc_test(rpc::client::RpcClient::ptr client) // rpc功能测试
{
    Json::Value params, result;
    params["num1"] = 11;
    params["num2"] = 22;
    bool ret = client->call("Add", params, result); // 同步rpc调用
    if (ret != false)
    {
        ILOG("result: %d", result.asInt());
    }
    rpc::client::RpcCaller::JsonAsyncResponse res_future;
    params["num1"] = 33;
    params["num2"] = 44;
    ret = client->call("Add", params, res_future); // 异步rpc调用
    if (ret != false)
    {
        result = res_future.get();
        ILOG("result: %d", result.asInt());
    }

    params["num1"] = 55;
    params["num2"] = 66;
    ret = client->call("Add", params, callback); // 回调rpc调用
    DLOG("-------\n");
}
int main()
{
    auto rpc_client = std::make_shared<rpc::client::RpcClient>(true, "127.0.0.1", 8080); // rpc请求客户端
    rpc_test(rpc_client);
    std::this_thread::sleep_for(std::chrono::seconds(5));
    return 0;
}